﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class LevelLoveIsACode : MonoBehaviour
{
    public string loveCode = ".-..---...-.";

    public Button buttonDian;
    public Button buttonGang;
    public Text loveCodeText;
    public GameObject loveBg;
    public List<Text> loveTextList = new List<Text>();
    private int tempIndex = 0;
    public GameLevelItem gameLevelItem;

    // Start is called before the first frame update
    void Start()
    {
        buttonDian.onClick.AddListener(() =>
        {
            SoundManager.Instance.PlayAudio(SoundType.Click.ToString(), false);
            loveCodeText.text = loveCodeText.text + ".";
            JudgeResult();
        });

        buttonGang.onClick.AddListener(() =>
        {
            SoundManager.Instance.PlayAudio(SoundType.Click.ToString(), false);
            loveCodeText.text = loveCodeText.text + "-";
            JudgeResult();
        });
    }

    private void JudgeResult()
    {
        if (loveCodeText.text.Equals(loveCode))
        {
            Debug.Log("love is a code level win");
            loveBg.SetActive(true);
            Invoke("ShowLoveLetter", 1);
        }
    }

    private void ShowLoveLetter()
    {
        if (tempIndex >= 4)
        {
            gameLevelItem.TriggerResult(true);
            return;
        }
        SoundManager.Instance.PlayAudio(SoundType.Drop.ToString(), false);
        loveTextList[tempIndex].enabled = true;
        tempIndex++;
        Invoke("ShowLoveLetter", 1);
    }
}
